<!DOCTYPE html>
<html>
<head>
    <title>发药--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>

</head>
<body>
<form id="myForm" `class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病历号</td>
        <td id="id" name="id">1101,1102,1104</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td id="registerName" name="registerName">黄飞鸿,黄飞鸿,黄飞鸿</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">药品名称</td>
        <td name="drug"><select id="drugs" name="drugId"><option>2304-九九感冒药</option></select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">发药数量</td>
        <td><input type="text" id="number" name="number"/></td>
    </tr>
    <tr>
        <td colspan="2">
			<center>
				<button onclick="giveDrugs()" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" onclick="black()">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>

<script type="text/javascript">
    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return decodeURI(r[2]); return null;
    }

    loadData();

    function showRefister(){
        let url = document.location.toString();
        let ids=url.GetValue("ids");
        let registerNames=url.GetValue("registerNames");
        let str1 = "";
        let str2 = "";
        for (let i =0;i<ids.length;i++){
            str1+= ids[i]+"";
        }
        for (let i =0;i<registerNames.length;i++){
            str2+= registerNames[i]+" ";
        }
        $("#id").html(str1);
        $("#registerName").html(str2);
    }
    function loadData() {
        $.ajax({
            type: "GET",
            url: "/drug/getDrugs",
            success: function (drug) {
                showRefister();
                let str = "";
                for (let i = 0;i<drug.length;i++){
                    str+='<option value="'+drug[i].id+'">'+drug[i].drugName+'</option>'
                }
                $("#drugs").html(str);
            }
        });
    }

    //发药
    function giveDrugs(){
        var id=$("#id").html();
        $.ajax({
            type:"POST",
            url:"/drugOut/addDrugOuts?id="+id,
            data:$("#myForm").serialize(),
            dataType:"json",
            success:function (vo) {
                if (vo.code===200){
                    alert("发药成功");
                    black();
                }else {
                    alert("发药失败！"+vo.msg);
                }
            }
        })
    }

    //返回
    function black(){
        window.location.href="dispensing.html";
    }
</script>
</body>
</html>